package com.own.component.util.excel.util.write.model;

import com.own.component.util.excel.util.write.function.FontFunction;
import com.own.component.util.excel.util.write.function.WriteFormatFunction;
import com.own.component.util.excel.util.write.style.base.AbstractStyleFunction;
import com.own.component.util.excel.util.write.style.item.StyleItemBorderStyle;
import com.own.component.util.excel.util.write.style.item.StyleItemHorizontalAlignment;
import com.own.component.util.excel.util.write.style.item.StyleItemVerticalAlignment;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Style excel样式类
 *
 * @author chenxueli
 * @date 2022-06-15 03:14:15
 */
@Builder
@Getter
@Setter
@ToString
@EqualsAndHashCode
public final class Style implements Serializable {

    public final static Style CENTER;
    public final static Style BORDER_THIN_BLACK;
    public final static Style BORDER_THIN_RED;

    static {
        CENTER = Style.builder()
                .build()
                .add(StyleItemHorizontalAlignment.CENTER)
                .add(StyleItemVerticalAlignment.CENTER);
        BORDER_THIN_BLACK = Style.builder()
                .build()
                .add(StyleItemHorizontalAlignment.CENTER)
                .add(StyleItemVerticalAlignment.CENTER)
                .add(StyleItemBorderStyle.THIN);
        BORDER_THIN_RED = Style.builder()
                .build()
                .add(StyleItemHorizontalAlignment.CENTER)
                .add(StyleItemVerticalAlignment.CENTER)
                .add(StyleItemBorderStyle.THIN);
    }

    /**
     * 其他属性列表
     */
    private List<AbstractStyleFunction<?>> styleList;
    /**
     * 字体
     */
    private FontFunction font;
    /**
     * 单元格格式
     */
    private Integer dataFormat;
    /**
     * 写入格式
     */
    private WriteFormatFunction writeFormat;

    /**
     * 追加属性信息
     *
     * @param fun 属性信息
     * @return 原样式
     */
    public Style add(AbstractStyleFunction<?> fun) {
        if (styleList == null) {
            styleList = new ArrayList<>();
        }
        styleList.add(fun);
        return this;
    }

}
